home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr48 / 386p_200.zip / PCX.ASM < prev    next >
Assembly Source File  |  1995-01-12  |  4KB  |  146 lines

  1. ; modulo per la visualizzazione di bitmap Pcx 320x200
  2. ; a 256 colori
  3. .386P
  4. code32 segment para public use32
  5.        assume cs:code32,ds:code32
  6.        
  7. include 386power.inc
  8. include 386video.inc
  9. include 386file.inc
  10.  
  11.         public _Pcx2Scr
  12.         public _PcxDecoded,_PcxHasPalette
  13.         public _PcxLoad        
  14.         public _PicPal
  15.         
  16.         align byte
  17. ; Palette extracted from last Pcx file read       
  18. _PicPal        db 768 dup(0)
  19.  
  20. _PcxDecoded    db 0
  21. _PcxHasPalette db 0
  22.  
  23. Pcx_len   dd 0
  24. Pcx_start dd 0
  25.  
  26. pcxx dd 0
  27. pcxy dd 0
  28.  
  29. scrpcx dd 0
  30.  
  31. _Pcx2Scr:
  32.         ; esi = Pcx data buffer base for a Pcx image
  33.         ;       smaller or equal to the current screen buffer size
  34.         ; eax = Pcx file lenght
  35.         ; expands the Pcx image to _ScrBase
  36.         ; starting from coordinates (0,0)
  37.         
  38.         pushad
  39.         mov Pcx_len,eax
  40.         mov Pcx_start,esi
  41.         mov _PcxDecoded,0    ; still have to decode it
  42.         mov _PcxHasPalette,0 ; still have to read palette
  43.         cmp dword ptr [esi],0801050Ah ; 8 bit/pix, RLE, Ver. 5, Pcx ???
  44.         jne Pcx_err  ; no, get out!
  45.         cmp byte ptr [esi+ 65],01     ; one plane ?
  46.         jne Pcx_err  ; no, get out!
  47.         
  48.         movzx eax,word ptr [esi+66] ; bytes * scanline
  49.         cmp eax,_ScrX
  50.         ja Pcx_err ; image too big
  51.         mov pcxx,eax
  52.         
  53.         movsx eax, word ptr [esi+10] ; ymax
  54.         movsx ebx, word ptr [esi+6 ] ; ymin
  55.         sub eax,ebx
  56.         inc eax
  57.         cmp eax,_ScrY
  58.         ja Pcx_err
  59.         mov pcxy,eax
  60.         
  61.         ; pcx image starting point at start of visible window
  62.         mov eax,_VDispY
  63.         mov edi,_VDispX
  64.         add edi,_ScrBase
  65.         add edi,[eax*4+_RowStart]
  66.         mov scrpcx,edi  ; set displacement from screen buffer start
  67.         
  68.         xor ecx,ecx
  69.         xor edx,edx
  70.         xor ebx,ebx
  71.         add esi,128  ; go to Pcx data block
  72. @yPcx:  
  73.         mov edi,[edx*4+_RowStart] ;
  74.         mov eax,pcxx
  75.         add edi,scrpcx
  76. @xPcx:
  77.         mov bl,[esi]
  78.         inc esi
  79.         mov cl,bl
  80.         cmp bl,0C0h   ; last 64 colors ?
  81.         jnb @Pcxburst ; then this is a RLE burst
  82.         ; else it is a single byte
  83.         mov [edi],cl
  84.         inc edi
  85.         dec eax
  86.         jnz @xPcx
  87.         jmp @linne
  88.                 
  89. @Pcxburst:
  90.         mov cl,[esi]
  91.         and ebx,03Fh    ; get count value
  92.         inc esi
  93.         sub eax,ebx
  94. buurst: mov [edi],cl
  95.         inc edi
  96.         dec ebx
  97.         jnz buurst
  98.         or eax,eax
  99.         jnz @xPcx
  100. @linne: ; new line of Pcx file
  101.         inc edx
  102.         cmp edx,pcxy
  103.         jb @yPcx
  104.         
  105.         ; now look for palette data and extract it
  106.         mov esi,Pcx_start
  107.         add esi,Pcx_len
  108.         sub esi,769
  109.         cmp byte ptr [esi],12
  110.         jne @paldone
  111.         mov _PcxHasPalette,1
  112.         inc esi
  113.         mov edi,offset _PicPal
  114.         mov ecx,256
  115. tre2quattro:
  116.         mov eax,[esi]
  117.         add esi,3
  118.         and eax,00FFFFFFh
  119.         stosd
  120.         dec ecx
  121.         jne tre2quattro
  122.         mov esi, offset _PicPal
  123.         call _Set256Pal
  124. @paldone:
  125.         ; Pcx file fully decode
  126.         mov _PcxDecoded,1      
  127. Pcx_err:
  128.         popad
  129.         ret
  130.                 
  131. _PcxLoad: ; DS:ESI == ASCIIZ name of Pcx file to load
  132.           ; Load pcx image into _ScrBase at _DisplayStart position
  133.           pushad
  134.           mov _PcxDecoded,0
  135.           call _FLoad
  136.           jc loaderr
  137.           mov esi,_HiMemBase
  138.           call _Pcx2Scr
  139.    loaderr:       
  140.           popad
  141.           ret
  142.           
  143. code32 ends
  144.  
  145.  END
  146.